import cv2
import numpy as np

#不改变原图大小，会丢失信息
def imgTranslate(img,xOffset,yOffset):
    rows=img.shape[0]
    cols=img.shape[1]
    dst=np.zeros((rows,cols,3),np.uint8)
    for i in range(0,rows):
        for j in range(0,cols):
            x=j+xOffset
            y=i+yOffset
            if(x>=0 and y>=0 and x<cols and y<rows):
                dst[y,x]=img[i,j]
    return dst

#改变原图大小，不丢失信息
def imgTranslate2(img,xOffset,yOffset):
    rows=img.shape[0]+abs(yOffset)
    cols=img.shape[1]+abs(xOffset)
    dst=np.zeros((rows,cols,3),np.uint8)
    for i in range(0,img.shape[0]):
        for j in range(0,img.shape[1]):
            x=j+xOffset
            y=i+yOffset
            if(x>=0 and y>=0 and x<cols and y<rows):
                dst[y,x]=img[i,j]
    return dst
